package com.xuecheng.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.CompanyVo;
import com.xuecheng.commons.model.vo.PageResponseResult;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.system.domain.Company;
import com.xuecheng.system.mapper.CompanyMapper;
import com.xuecheng.system.service.CompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 教育机构 服务实现类
 * </p>
 *
 * @author itheima
 * @since 2022-07-29
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {

    @Override
    public ResponseResult find(PageRequest request) {
        //构建分页
        Page<Company> page = new Page<>(request.getPageNo(), request.getPageSize());
        //构建条件
        //LambdaQueryWrapper<Company> qw = new LambdaQueryWrapper<>();
        // 课程名称
        //String courseName = dto.getCourseName();
        //qw.like(StrUtil.isNotBlank(courseName), CourseBase::getName, courseName);
        // 课程状态
        //String auditStatus = dto.getAuditStatus();
        //qw.eq(StrUtil.isNotBlank(auditStatus), CourseBase::getAuditStatus, auditStatus);
        // 课程类型
        //String teachmode = dto.getTeachmode();
        //qw.eq(StrUtil.isNotBlank(teachmode), CourseBase::getTeachmode, teachmode);
        //执行分页查询

        page = this.page(page);
        List<Company> list = page.getRecords();
        for (Company company : list) {
            company.setCompanyId(company.getId().toString());
        }
        //List<CompanyVo> voList=new ArrayList<>();
        //for (Company company : list) {
        //    CompanyVo companyVo = BeanHelper.copyProperties(company, CompanyVo.class);
        //    companyVo.setCompanyId(company.getId());
        //voList.add(companyVo);
        //}
        //返回分页结果
        return PageResponseResult.okResult((long) list.size(), list);
    }

    @Override
    public Company findId(String id) {
        Company byId = getById(id);
       // CompanyVo companyVo = BeanHelper.copyProperties(byId, CompanyVo.class);
        return byId;
    }
}

